import React from 'react'
import actionCreators  from '../store/actionCreators/counter1';
import store from '../store';
import { bindActionCreators } from '../redux';

const boundActions = bindActionCreators(actionCreators,store.dispatch)

export default class Counter1 extends React.Component {
    constructor(props) {
        super(props);
        this.state = { title:'计数器1' ,...store.getState().counter1}
    }
    componentDidMount(){
        this.un = store.subscribe(()=>{
            this.setState(store.getState().counter1)
        })
    }
    componentWillUnmount(){
        this.un()
    }
    render(){
        return (
            <div>
                <p>{this.state.number}</p>
                {/* <button onClick={()=>store.dispatch(add())}>+</button>
                <button onClick={()=>store.dispatch(minus())}>-</button> */}
                <button onClick={boundActions.add1}>+</button>
                <button onClick={boundActions.minus1}>-</button>
            </div>
        )
    }
}
